<%@page import="java.sql.SQLException"%>
<%@page import="org.apache.jasper.tagplugins.jstl.core.Catch"%>
<%@page import="java.rmi.RemoteException"%>
<%@page import="exception.FriendNotFoundException"%>
<%@page import="exception.NotLoggedInException"%>
<%@page import="java.rmi.Naming"%>
<%@page import="clientData.MemberDataInt"%>
<%@page import="java.util.LinkedList"%>
<%@page import="server.ForumHandlerInt"%>
<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>

<%@ include file="serverConnection.jsp" %>
<%
	
	LinkedList<MemberDataInt> friends = null;
	String friendUserNameToRemove = request
			.getParameter("friendToRemove");
	if (friendUserNameToRemove == null) {
		response.sendRedirect("friends.jsp");
		response.flushBuffer();
		return;
	}
	String userName = (String) session.getAttribute("userName");
	String password = (String) session.getAttribute("password");
	if ((userName == null) || (password == null)) {
		response.sendRedirect("loggin.jsp");
		response.flushBuffer();
		return;
	}
	

	try{
		forum.removeFriend(userName, password, friendUserNameToRemove);
		friends = forum.getUserFriends(userName,password);
	}catch(FriendNotFoundException s){
		   
		   
		   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
			"no such friend");
		
			response.flushBuffer();
			return;
		   
		   
	   }
			catch(NotLoggedInException t)
			{
				response.sendRedirect("loggin.jsp");
				response.flushBuffer();
				return;
			}
				catch(SQLException s){
					   
					   
					   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
						"SQL server is down");
					
						response.flushBuffer();
						return;
					   
					   
				   }
				   catch(RemoteException u){
					   
					   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
						"forum server is down");
					
						response.flushBuffer();
						return;
				   }	
%>
<select id="friendsList" name="friendsList" size="10">
	<%
		for (MemberDataInt friend : friends) {
	%><option value="<%=friend.getUserName()%>"><%=friend.getUserName()%></option>
	<%
		}
	%>
</select>


